package com.example.hotelback.utils;

import lombok.Data;

/**
 * 封装统一的返回数据结构
 */
@Data
public class Result {

    private String code; //返回的状态码
    private String msg; //后台报错信息
    private Object data; //返回的数据 object可以接收任何对象

    private static final String SUCCESS = "0";
    private static final String ERROR = "1";

    //静态方法 通过对象名直接调用
    public static Result success() {
        Result result = new Result();
        result.setCode(SUCCESS);
        return result;
    }

    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(ERROR);
        result.setMsg(msg);
        return result;
    }

}
